package di.scanner.executor;

import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class ThreadPool  {

    public final static String FILE_CONSUMER_POOL = "file pool";
    public final static String CLASS_CONSUMER_POOL = "class pool";

    private ConcurrentHashMap<String,ExecutorService> pool;

    private ThreadPool() {
        pool = new ConcurrentHashMap<>();
        pool.put(FILE_CONSUMER_POOL, Executors.newFixedThreadPool(5));
       // pool.put(CLASS_CONSUMER_POOL,Executors.newFixedThreadPool(5));
    }

    private static ThreadPool threadPool;

    public static ThreadPool getInstance(){
        if (threadPool==null){
            synchronized (ThreadPool.class){
                if (threadPool==null){
                    threadPool = new ThreadPool();
                }
            }
        }
        return threadPool;
    }

    public ExecutorService getThreadPool(String name){
        return pool.get(name);
    }

}
